<?php

namespace app\models;

use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
use yii\data\Pagination;
use yii\data\ActiveDataProvider;
use yii\data\Sort;
use yii\helpers\Inflector;

class StaffRelaSearch extends StaffRela
{

    public $region_name;
    public $user_name;


    public static function tableName()
    {
        return StaffRela::tableName();
    }

    public function rules()
    {
        return [
//            [['region_id'], 'safe'],
//            [['region_name'], 'safe'],
//            [['cust_limit'], 'safe'],


        ];
    }


    public function search($params, $user_id=null)
    {
        $where = [];
        $query = StaffRela::find()->alias('a');
        $query->joinWith('staffs  AS b');


        $where['a.user_id'] = $user_id;


//        // 查询某人创建的所有订单
//        if ($create_user_id)
//        {
//            $where['a.create_staff_id'] = $create_user_id;
//        }





        if ($where)
        {
            $query->where($where);
        }

        $sort = new Sort([
            'attributes' => [
                'create_date',
            ],
        ]);




        $query->orderBy($sort->orders);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'defaultOrder' => [
                    'create_date' => SORT_DESC,
                ]
            ],
            'pagination' => [
                'pageSize' => 50,
            ],
        ]);



        if (!($this->load($params) )) {
            return $dataProvider;
        }

      //  $query->andFilterWhere(['like', 'a.remark', $this->remark]);

//        $query->andFilterWhere(['like', 'c.cust_name', $this->cust_name]);
//        $query->andFilterWhere(['like', 'd.prod_name', $this->prod_name]);
//
//        $query->andFilterWhere(['like', 'd.username', $this->user_name]);
//        $query->andFilterWhere(['like', 'e.username', $this->staffName]);

        return $dataProvider;


    }


}

?>
